package com.zenitera.bigdata.source;

import com.zenitera.bigdata.bean.Test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Flink06_Source_MysqlTest {
    public static void main(String[] args) throws Exception {
        String driver = "com.mysql.jdbc.Driver";
        String url = "jdbc:mysql://localhost:3306/flinkcdc";
        String username = "root";
        String password = "123456";
        Connection connection = null;
        Statement statement = null;

        try {
            //加载驱动
            Class.forName(driver);
            //创建连接
            connection = DriverManager.getConnection(url, username, password);
            //获取执行语句
            statement = connection.createStatement();
            //执行查询，获得结果集
            ResultSet resultSet = statement.executeQuery("select * from test");
            //处理结果集
            while (resultSet.next()) {
                Test test = new Test(
                        resultSet.getInt("id"),
                        resultSet.getString("name").trim(),
                        resultSet.getString("updated").trim(),
                        resultSet.getString("eutime").trim());
                System.out.println(test);
            }

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (connection != null) {
                connection.close();
            }
            if (statement != null) {
                connection.close();
            }
        }

    }
}
